package com.hm.service.impl.ydcg;

import com.hm.service.entity.ydcg.CasePushTimeBean;
import com.hm.service.mapper.recording.CasePushTimeMapper;
import com.hm.service.service.main.CasePushTimeService;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class CasePushTimeServiceImpl implements CasePushTimeService {

    @Qualifier("MainSqlSessionFactory")
    private final SqlSessionFactory sqlSessionFactory;

    public CasePushTimeServiceImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public String getTime() {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            CasePushTimeMapper mapper = session.getMapper(CasePushTimeMapper.class);
            HashMap<String, String> params = new HashMap<>();
            params.put("queryId", "10011");
            CasePushTimeBean time = mapper.getTime(params);
            return time.lastUpdateTime;
        }
    }


    @Override
    public void saveTime(String currentTime) {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            CasePushTimeMapper mapper = session.getMapper(CasePushTimeMapper.class);
            HashMap<String, String> currentTimeParams = new HashMap<>();
            currentTimeParams.put("queryId", "10011");
            currentTimeParams.put("curryTime", currentTime);
            mapper.saveTime(currentTimeParams);
        }
    }
}
